Nested for loop in Python to get equivalent result

join shbcf.ru